// pages/newResults/newResults.js
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        activeNames: ['0'],
        array: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'],
        index: 0,
        activeNames: ['0'],
        id: 0,
        num_sn: null,
        predict: null,
        is_get_profit: null,
        ke_zhu_idea: null,
        zixun_wants: null,
        things_degree: null,
        customer_xintai: null,
        zixun_xintai: null,
        customer_xinli: null,
        zixun_xinli: null,
        solution: null,
        is_good: null,
        health_status: null,
        // 是否展示时间节点预测
        is_show_time_res: 1,
        // 序言
        preface: '另⼀⽅(包括外界环境和市场)的发展时间进展',
        twenty_years_predict: '',
        years_predict: '',
        month_predict: '',
        day_predict: '',
        // 有当事人
        ds_twenty_years_predict: '',
        ds_years_predict: '',
        ds_month_predict: '',
        ds_day_predict: '',
        // 用户提问信息
        person_tpl: '',
        // 用户来源的 history_id,
        history_id: 0,
        queryTypes: 0,
        itypes: 0,
        detail: null,
        me: '我方',
        ta: '另一方',
        xzdata1: false,
        isHidden: 2,
        xztype: 1,
        urls: '',
        payShow: false,
        cid3: 0,
        btnShow: 'hidden',
        question_id: 0,
        //是否是反向提问
        reverse: 0,
        qus_msg: '',
        qus_msg1: '',
        types: 0,
        theme: '',
        loginsrc: '',
        huaweilogin: '',
        canvasHeight: 1125,
        canvasWidth: null,
        canvas: null,
        // 日期展示: 2024-2043, 点击后展示会与不会. 默认不展示
        showDateIsCan: 0,
        hiddenClick: 1,
        // 当前 提问是否 指定了时间
        isAssignDate: false,
        // 特殊编号的 标志
        is_special: 0,
        month_good: '',
        day_good: '',
        // 没有日期下的 有无利益
        last_num_text: '',
        // 容易|困难
        date_diff: '',
    },
    init: function () {
        const query = wx.createSelectorQuery()
        try {
            var res = wx.getSystemInfoSync();
            this.setData({
                canvasHeight: 1125,
                canvasWidth: res.windowWidth
            })
        } catch (e) {
            console.error('getSystemInfoSync failed!');
        }
        var vm = this
        query.select('#myCanvas')
            .fields({
                node: true,
                size: true
            })
            .exec((res) => {
                const canvas = res[0].node
                this.setData({ //这里保存canvas对象是因为下面保存相片要用这个对象
                    canvas
                })
                const ctx = canvas.getContext('2d')
                const dpr = wx.getSystemInfoSync().pixelRatio
                canvas.width = res[0].width * dpr // 获取宽
                canvas.height = res[0].height * dpr // 获取高
                ctx.scale(dpr, dpr)

                // 到这里就可以直接绘制
                let image = canvas.createImage(); //创建iamge实例
                // image.src = 'https://aiw.oss-cn-beijing.aliyuncs.com/v3/xq_bg@2x.png';  // 引入本地图片
                image.src = this.data.theme == 'style1' ? '../../images/bg22.png' : 'https://aiw.oss-cn-beijing.aliyuncs.com/v3/xq_bg@2x.png'; // 引入本地图片
                image.onload = function () {
                    ctx.drawImage(image, 0, 0, vm.data.canvasWidth, vm.data.canvasHeight); // 背景图
                }
                setTimeout(() => {
                    // ctx.clearRect(25, 25, vm.data.canvasWidth - 50, 140);
                    // ctx.fillStyle = '#03239F'
                    // 指定透明颜色，用于描边和填充样式
                    ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : '#03239F'
                    ctx.fillRect(25, 25, vm.data.canvasWidth - 50, 140);
                    ctx.save()

                    ctx.font = '15px'
                    ctx.fillStyle = 'rgba(0, 216, 255, 1)'
                    ctx.fillText(`编号:@${vm.data.detail.num_sn ? vm.data.detail.num_sn : ''}`, 35, 45)
                    ctx.save()
                    ctx.font = '20px'
                    ctx.fillStyle = '#FFFFFF'
                    vm.drawTxt(ctx, vm.data.qus_msgt, 30, vm.data.canvasWidth - 50 - 50, 35, 75)
                    ctx.save()
                    let image1 = canvas.createImage(); //创建iamge实例
                    image1.src = '../../images/wuming 2_lightblue.png'; // 引入本地图片
                    image1.onload = function () {
                        ctx.drawImage(image1, vm.data.canvasWidth / 3 - 70, 190, 70, 70); // 背景图
                    }
                    let image2 = canvas.createImage(); //创建iamge实例
                    image2.src = 'https://aiw.oss-cn-beijing.aliyuncs.com/huawei1.png'; // 引入本地图片
                    image2.onload = function () {
                        ctx.drawImage(image2, (vm.data.canvasWidth / 3 + vm.data.canvasWidth / 3) - 100, 190, 70, 70); // 背景图
                    }
                    let image3 = canvas.createImage(); //创建iamge实例
                    image3.src = '../../images/kc.png'; // 引入本地图片
                    image3.onload = function () {
                        ctx.drawImage(image3, (vm.data.canvasWidth / 3 + vm.data.canvasWidth / 3), 190, 70, 70); // 背景图
                    }
                    ctx.save()
                    ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : 'rgba(0, 13, 132, 0.600000)'
                    ctx.fillRect(25, 275, vm.data.canvasWidth - 50, 50);
                    ctx.fillRect(25, 335, vm.data.canvasWidth - 50, 50);
                    ctx.save()
                    ctx.font = '15px'
                    ctx.fillStyle = '#FFFFFF'
                    if (vm.data.detail.rate_value == 1) {
                        ctx.fillText('指定监测预警推送频率（非必选）', 35, 305)
                        let day = vm.data.array[vm.data.index];
                        if (day == undefined) {
                            day = 0;
                        }
                        ctx.fillText(day + `天`, vm.data.canvasWidth - 75, 305)
                    }
                    ctx.fillText('用户选择为', 35, 365)
                    ctx.fillText(`${vm.data.detail.contact_text}`, vm.data.canvasWidth - 75, 365)
                    ctx.save()
                    // 设置边框样式
                    ctx.strokeStyle = vm.data.theme == 'style1' ? 'rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                    ctx.lineWidth = 1 // 设置边框宽度
                    // 绘制矩形边框
                    ctx.strokeRect(25, 405, (vm.data.canvasWidth - 52), 130); // 参数依次为边框左上角
                    if (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59 && vm.data.detail.question_id != 75) {
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_1, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 417)
                    }

                    vm.drawTxt(ctx, vm.data.detail.result_title.title_2, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 417)
                    vm.drawTxt(ctx, vm.data.detail.result_title.title_3, 15, (vm.data.canvasWidth - 50) / 3 - 13, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3, 417)
                    ctx.moveTo(vm.data.canvasWidth / 3 + 10, 405)
                    ctx.lineTo((vm.data.canvasWidth) / 3 + 10, 535)
                    ctx.stroke()
                    ctx.moveTo(vm.data.canvasWidth / 3 + vm.data.canvasWidth / 3, 405)
                    ctx.lineTo((vm.data.canvasWidth) / 3 + vm.data.canvasWidth / 3, 535)
                    ctx.stroke()
                    ctx.save()
                    if (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59 && vm.data.detail.question_id != 75) {
                        vm.drawTxt(ctx, vm.data.detail.is_get_profit, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 470)
                    }

                    vm.drawTxt(ctx, vm.data.detail.me_wants, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 470)
                    vm.drawTxt(ctx, vm.data.detail.ta_idea, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3 + 10, 470)
                    ctx.save()

                    ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : 'rgba(0, 13, 132, 0.600000)'
                    ctx.strokeStyle = vm.data.theme == 'style1' ? '(rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                    ctx.lineWidth = 1 // 设置边框宽度
                    console.log('----', vm.data.detail.q_flag);
                    if (vm.data.detail.is_show_time_res == 0 && vm.data.detail.q_flag == 1) { // 6
                        ctx.fillRect(25, 535, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 565)
                        ctx.lineTo(vm.data.canvasWidth - 25, 565)
                        ctx.stroke()

                        ctx.fillRect(25, 565, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 595)
                        ctx.lineTo(vm.data.canvasWidth - 25, 595)
                        ctx.stroke()

                        ctx.fillRect(25, 595, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 625)
                        ctx.lineTo(vm.data.canvasWidth - 25, 625)
                        ctx.stroke()

                        ctx.fillRect(25, 625, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 655)
                        ctx.lineTo(vm.data.canvasWidth - 25, 655)
                        ctx.stroke()

                        ctx.fillRect(25, 655, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 685)
                        ctx.lineTo(vm.data.canvasWidth - 25, 685)
                        ctx.stroke()

                        ctx.save()
                        ctx.fillRect(25, 685, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 715)
                        ctx.lineTo(vm.data.canvasWidth - 25, 715)
                        ctx.stroke()
                        ctx.save()
                        ctx.strokeStyle = vm.data.theme == 'style1' ? '(rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                        ctx.lineWidth = 1 // 设置边框宽度
                        // 绘制矩形边框
                        if (vm.data.detail.is_show_time_res == 0 && vm.data.detail.q_flag == 1) {
                            ctx.strokeRect(vm.data.canvasWidth - 70, 540, 35, 20); // 参数依次为边框左上角
                            ctx.strokeRect(vm.data.canvasWidth - 70, 570, 35, 20); // 参数依次为边框左上角
                            ctx.strokeRect(vm.data.canvasWidth - 70, 600, 35, 20); // 参数依次为边框左上角
                        }
                        if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 1) {
                            ctx.strokeRect(vm.data.canvasWidth - 70, 630, 35, 20); // 参数依次为边框左上角
                        }
                        if (vm.data.detail.is_show_time_res == 1) {
                            ctx.strokeRect(vm.data.canvasWidth - 70, 660, 35, 20); // 参数依次为边框左上角
                        }
                        ctx.strokeRect(vm.data.canvasWidth - 75, 690, 47, 20); // 参数依次为边框左上角

                        ctx.save()
                        ctx.font = '13px'
                        ctx.fillStyle = '#FFFFFF'
                        if (vm.data.detail.is_show_time_res == 0 && vm.data.detail.q_flag == 1) {
                            //   ctx.fillText(`年：${vm.data.detail.year_good}`, 35, 555)
                            ctx.fillText(`年：2024-2043`, 35, 555)
                            ctx.fillText(`${vm.data.detail.date_diff}`, vm.data.canvasWidth - 65, 555)
                            ctx.fillText(`月：${vm.data.detail.month_good}`, 35, 585)
                            ctx.fillText(`容易`, vm.data.canvasWidth - 65, 585)
                            //   ctx.fillText(`日：${vm.data.detail.day_good}`, 35, 615)
                            vm.drawTxt(ctx, `日：${vm.data.detail.day_good}`, 15, (vm.data.canvasWidth) - 150, 35, 615)
                            ctx.fillText(`容易`, vm.data.canvasWidth - 65, 615)
                        }
                        if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 1) {
                            ctx.fillText(`${vm.data.detail.startenddate}`, 35, 645)
                            if (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59) {
                                ctx.fillText(`${vm.data.detail.date_text}`, vm.data.canvasWidth - 65, 645)
                                ctx.font = 'normal bold 36px Arial,sans-serif '
                            }

                        } else if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 0) {
                            console.log(111)
                            ctx.font = '20px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText(`付费查看`, vm.data.canvasWidth / 2 - 40, 555)
                        }
                        if (vm.data.detail.is_show_time_res == 1 && vm.data.detail.time_pay == 1 && vm.data.detail.question_id != 58) {
                            ctx.fillText(`${vm.data.detail.date1}`, 35, 675)
                            ctx.font = '20px'
                            ctx.fillText(`${vm.data.detail.easy == 1 ? '会' : '不会'}`, vm.data.canvasWidth - 65, 675)
                        }
                        if (vm.data.detail.contact != 2 && (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59 && vm.data.detail.question_id != 75)) {
                            ctx.fillText(`有无利益:`, 35, 705)
                            ctx.fillText(`${vm.data.detail.last_num_text}`, vm.data.canvasWidth - 70, 705)
                        }
                        if (vm.data.detail.contact != 2 && (vm.data.detail.question_id == 58 || vm.data.detail.question_id == 59)) {
                            ctx.fillText(`健康状态:`, 35, 705)
                            ctx.fillText(`${vm.data.detail.health_status}`, vm.data.canvasWidth - 300, 705)
                        }
                        ctx.save()


                        ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : 'rgba(0, 13, 132, 0.600000)'
                        ctx.strokeStyle = vm.data.theme == 'style1' ? '(rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                        ctx.lineWidth = 1 // 设置边框宽度

                        ctx.strokeRect(25, 718, (vm.data.canvasWidth - 52), 130); // 参数依次为边框左上角
                        ctx.save()
                        ctx.fillStyle = '#FFFFFF'
                        ctx.font = '15px'
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_8, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 730)
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_9, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 730)
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_10, 15, (vm.data.canvasWidth - 50) / 3 - 13, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3, 730)
                        ctx.moveTo(vm.data.canvasWidth / 3 + 10, 718)
                        ctx.lineTo((vm.data.canvasWidth) / 3 + 10, 845)
                        ctx.stroke()
                        ctx.moveTo(vm.data.canvasWidth / 3 + vm.data.canvasWidth / 3, 718)
                        ctx.lineTo((vm.data.canvasWidth) / 3 + vm.data.canvasWidth / 3, 845)
                        ctx.stroke()
                        ctx.save()
                        vm.drawTxt(ctx, vm.data.detail.me_xintai, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 767)
                        vm.drawTxt(ctx, vm.data.detail.things_degree, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 767)
                        vm.drawTxt(ctx, vm.data.detail.me_xinli, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3, 767)
                        ctx.save()

                        ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : '#03239F'
                        ctx.fillRect(25, 860, vm.data.canvasWidth - 50, 80);
                        ctx.save()
                        ctx.font = '20px'
                        ctx.fillStyle = '#FFFFFF'
                        ctx.fillText(`- 以下为何以解决问题的方法 -`, vm.data.canvasWidth / 2 - 130, 877)
                        ctx.save()


                        if (vm.data.detail.resolve_pay == 1) { //支付
                            ctx.font = '15px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText('另一方希望我方', 35, 910)
                            ctx.fillText(`${vm.data.detail.solution}`, 35, 930)
                        } else {
                            ctx.font = '20px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText(`付费查看`, vm.data.canvasWidth / 2 - 40, 918)
                        }
                        let image3 = canvas.createImage(); //创建iamge实例
                        image3.src = vm.data.detail.qrcode; // 引入本地图片
                        image3.onload = function () {
                            ctx.drawImage(image3, vm.data.canvasWidth / 2 - 80, 950, 160, 160); // 背景图
                        }
                    } else {

                        // ---
                        ctx.fillRect(25, 535, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 565)
                        ctx.lineTo(vm.data.canvasWidth - 25, 565)
                        ctx.stroke()

                        ctx.fillRect(25, 565, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 595)
                        ctx.lineTo(vm.data.canvasWidth - 25, 595)
                        ctx.stroke()

                        ctx.fillRect(25, 595, vm.data.canvasWidth - 50, 30);
                        ctx.moveTo(25, 625)
                        ctx.lineTo(vm.data.canvasWidth - 25, 625)
                        ctx.stroke()
                        ctx.strokeStyle = vm.data.theme == 'style1' ? '(rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                        ctx.lineWidth = 1 // 设置边框宽度
                        // 绘制矩形边框
                        // if (vm.data.detail.is_show_time_res == 0 && vm.data.detail.q_flag == 1) {
                        //   ctx.strokeRect(vm.data.canvasWidth - 70, 540, 35, 20); // 参数依次为边框左上角
                        //   ctx.strokeRect(vm.data.canvasWidth - 70, 570, 35, 20); // 参数依次为边框左上角
                        //   ctx.strokeRect(vm.data.canvasWidth - 70, 600, 35, 20); // 参数依次为边框左上角
                        // }
                        if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 1) {
                            ctx.strokeRect(vm.data.canvasWidth - 70, 540, 35, 20); // 参数依次为边框左上角
                        }
                        if (vm.data.detail.is_show_time_res == 1) {
                            ctx.strokeRect(vm.data.canvasWidth - 70, 570, 35, 20); // 参数依次为边框左上角
                        }

                        ctx.strokeRect(vm.data.canvasWidth - 75, 600, 47, 20); // 参数依次为边框左上角

                        ctx.save()
                        ctx.font = '13px'
                        ctx.fillStyle = '#FFFFFF'
                        // if (vm.data.detail.is_show_time_res == 0 && vm.data.detail.q_flag == 1) {
                        //   ctx.fillText(`年：${vm.data.detail.year_good}`, 35, 555)
                        //   ctx.fillText(`容易`, vm.data.canvasWidth - 65, 555)
                        //   ctx.fillText(`月：${vm.data.detail.month_good}`, 35, 585)
                        //   ctx.fillText(`容易`, vm.data.canvasWidth - 65, 585)
                        //   ctx.fillText(`日：${vm.data.detail.day_good}`, 35, 615)
                        //   ctx.fillText(`容易`, vm.data.canvasWidth - 65, 615)
                        // }
                        if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 1) {
                            ctx.fillText(`${vm.data.detail.startenddate}`, 35, 555)
                            ctx.font = '30px'
                            if (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59) {
                                ctx.fillText(`${vm.data.detail.date_text}`, vm.data.canvasWidth - 65, 555)
                            }

                        } else if (vm.data.detail.startenddate.length > 0 && vm.data.detail.time_pay == 0) {
                            console.log(222)
                            ctx.font = '30px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText(`付费查看`, vm.data.canvasWidth / 2 - 40, 555)
                        }
                        if (vm.data.detail.is_show_time_res == 1 && vm.data.detail.time_pay == 1 && vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59 && vm.data.detail.question_id != 75) {
                            ctx.fillText(`${vm.data.detail.date1}`, 35, 585)
                            ctx.fillText(`${vm.data.detail.easy == 1 ? '会' : '不会'}`, vm.data.canvasWidth - 65, 585)
                        }
                        if (vm.data.detail.contact != 2 && (vm.data.detail.question_id != 58 && vm.data.detail.question_id != 59 && vm.data.detail.question_id != 75)) {
                            ctx.fillText(`有无利益:`, 35, 615)
                            ctx.fillText(`${vm.data.detail.last_num_text}`, vm.data.canvasWidth - 70, 615)
                        }
                        if (vm.data.detail.contact != 2 && (vm.data.detail.question_id == 58 || vm.data.detail.question_id == 59 || vm.data.detail.question_id == 75)) {
                            ctx.fillText(`健康状态:`, 35, 615)
                            ctx.fillText(`${vm.data.detail.health_status}`, vm.data.canvasWidth - 300, 615)
                        }
                        ctx.save()

                        ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : 'rgba(0, 13, 132, 0.600000)'
                        ctx.strokeStyle = vm.data.theme == 'style1' ? '(rgb(148, 130, 148)' : '#1644AD' // 设置边框颜色
                        ctx.lineWidth = 1 // 设置边框宽度

                        ctx.strokeRect(25, 628, (vm.data.canvasWidth - 52), 130); // 参数依次为边框左上角
                        ctx.save()
                        ctx.fillStyle = '#FFFFFF'
                        ctx.font = '15px'
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_8, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 640)
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_9, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 640)
                        vm.drawTxt(ctx, vm.data.detail.result_title.title_10, 15, (vm.data.canvasWidth - 50) / 3 - 13, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3, 640)
                        ctx.moveTo(vm.data.canvasWidth / 3 + 10, 628)
                        ctx.lineTo((vm.data.canvasWidth) / 3 + 10, 755)
                        ctx.stroke()
                        ctx.moveTo(vm.data.canvasWidth / 3 + vm.data.canvasWidth / 3, 628)
                        ctx.lineTo((vm.data.canvasWidth) / 3 + vm.data.canvasWidth / 3, 755)
                        ctx.stroke()
                        ctx.save()
                        vm.drawTxt(ctx, vm.data.detail.me_xintai, 15, (vm.data.canvasWidth - 50) / 3 - 13, 30, 677)
                        vm.drawTxt(ctx, vm.data.detail.things_degree, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + 10, 677)
                        vm.drawTxt(ctx, vm.data.detail.me_xinli, 15, (vm.data.canvasWidth - 50) / 3, (vm.data.canvasWidth) / 3 + (vm.data.canvasWidth) / 3, 677)
                        ctx.save()

                        ctx.fillStyle = vm.data.theme == 'style1' ? "rgba(171, 53, 44,0.34)" : '#03239F'
                        ctx.fillRect(25, 770, vm.data.canvasWidth - 50, 80);
                        ctx.save()
                        ctx.font = '20px'
                        ctx.fillStyle = '#FFFFFF'
                        ctx.fillText(`- 以下为何以解决问题的方法 -`, vm.data.canvasWidth / 2 - 130, 787)
                        ctx.save()


                        if (vm.data.detail.resolve_pay == 1) { //支付
                            ctx.font = '15px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText('另一方希望我方', 35, 820)
                            ctx.fillText(`${vm.data.detail.solution}`, 35, 840)
                        } else {
                            ctx.font = '20px'
                            ctx.fillStyle = '#FFFFFF'
                            ctx.fillText(`付费查看`, vm.data.canvasWidth / 2 - 40, 828)
                        }
                        let image3 = canvas.createImage(); //创建iamge实例
                        image3.src = vm.data.detail.qrcode; // 引入本地图片
                        image3.onload = function () {
                            ctx.drawImage(image3, vm.data.canvasWidth / 2 - 80, 860, 160, 160); // 背景图
                        }
                    }

                }, 1000)
            })
    },
    // 生成图片
    saveImage() {
        this.init()
        wx.showToast({
            title: "生成图片中...",
            duration: 5000
        })
        setTimeout(() => {
            console.log(13);
            wx.canvasToTempFilePath({
                canvasId: 'myCanvas',
                destWidth: this.data.canvasWidth,
                destHeight: this.data.canvasHeight + 40,
                canvas: this.data.canvas,
                success: (res) => {
                    console.log('--', res);
                    // this.setData({
                    //   tempFilePath: res.tempFilePath
                    // })
                    console.log('--', res.tempFilePath);
                    wx.saveImageToPhotosAlbum({ //保存图片到相册
                        filePath: res.tempFilePath,
                        success: function () {
                            wx.showToast({
                                title: "生成图片成功！",
                                duration: 1500
                            })
                        },
                        fail: function (err) {
                            console.log('--err', err);

                        }
                    })
                }
            });
        }, 5500)

    },
    drawTxt(ctx, text, lineHeight = 30, maxWidth, x, y) {
        const words = text.split('\n'); // 按换行符分割文本为多行
        words.forEach((word) => {
            let line = ''; // 当前行的文本
            const characters = word.split(''); // 按字符分割文本
            characters.forEach((character) => {
                const testLine = line + character;
                const metrics = ctx.measureText(testLine);
                const testWidth = metrics.width;
                if (testWidth > maxWidth) {
                    ctx.font = '15px'
                    ctx.fillText(line, x, y);
                    line = character;
                    y += lineHeight;
                } else {
                    line = testLine;
                }
            });
            ctx.font = 38;
            ctx.font = '15px'
            ctx.fillText(line, x, y);
            y += lineHeight;
        });
    },
    /**
     * 折叠面板
     */
    changeIcon(e) {
        let seq = e.currentTarget.dataset.seq;
        let arr = this.data.activeNames;

        if (arr.indexOf(seq) > 0) {
            arr[seq] = 0;
            this.data.activeNames = arr;
            this.setData({
                activeNames: arr
            });
            // console.log('有--删除::', arr, this.data.activeNames);
        } else {
            arr[seq] = seq;
            this.data.activeNames = arr;
            this.setData({
                activeNames: arr
            });
            // console.log('无--删除::', arr, this.data.activeNames);        
        }
    },
    onShow() {
        if (wx.getStorageSync('theme') == 'style1') {
            this.setData({
                theme: 'style1',
                loginsrc: 'https://aiw.oss-cn-beijing.aliyuncs.com/logo.png',
                huaweilogin: 'https://aiw.oss-cn-beijing.aliyuncs.com/huawei1.png'

            })
        } else {
            this.setData({
                theme: 'init',
                loginsrc: 'https://aiw.oss-cn-beijing.aliyuncs.com/logo.png',
                huaweilogin: 'https://aiw.oss-cn-beijing.aliyuncs.com/huawei1.png'
            })
        }
        this.init()
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let cacheUserInfo = wx.getStorageSync('user_phone');
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : ''
        let that = this
        let history_id = options.history_id;
        let question_id = options.question_id;
        let flag = options.flag;
        let isHidden = options.isHidden;

        let isIos = 0; //ios标志
        let resType = wx.getSystemInfoSync();
        if (resType.platform == 'ios') {
            isIos = 1;
        }
        console.log(options);
        let reverse = wx.getStorageSync('reverse') ? wx.getStorageSync('reverse') : 0;
        if ((question_id == 8 || question_id == 10 || question_id == 54 || question_id == 7) && reverse == 0) {
            this.setData({
                btnShow: 'show'
            })
        } else {
            this.setData({
                btnShow: 'hidden'
            })
        }

        this.setData({
            question_id: question_id,
            history_id: history_id,
            me: user_phone,
            cid3: options.cid3,
            xzdata1: options.xzdata1,
            xztype: options.xztype,
            flag: options.flag,
            isHidden: options.isHidden
        })

        var reqUri = app.globalData.domain + 'v4/index/getPredict';

        wx.request({
            url: reqUri,
            data: {
                history_id: history_id,
                flag: flag,
                isHidden: isHidden,
                isIos: isIos
            },
            success(res) {
                if (res.data.code == app.globalData.successCode) {
                    let qus_msg = res.data.data.question_msg;
                    let qus_msg1 = '';
                    if (reverse == 1 && question_id == 7) {
                        wx.getStorage({
                            key: 'questionInfo',
                            success(questionInfo) {
                                qus_msg1 = '现状态下' + questionInfo.data.title1 + ',' + questionInfo.data.date1 + '(年月日)会同意给我' + questionInfo.data.title3;
                                that.setData({
                                    qus_msgt: qus_msg1,
                                })
                            }
                        })
                    }
                    // 如果date1, 是 年月 或者 年月日的组合, 不显示 2024-2043
                    var dates = res.data.data.date1;
                    var arr = [];

                    // 如果没有日期
                    console.log('dates:', dates.length, typeof (dates));
                    if (dates.length != 0 && dates != undefined) {
                        that.setData({
                            isAssignDate: true
                        });
                    }

                    if (!dates || dates != undefined) arr = dates.split('-');

                    if (arr.length > 1) that.setData({
                        showDateIsCan: 1,
                        hiddenClick: 0
                    });

                    that.setData({
                        detail: res.data.data,
                        index: res.data.data.rate,
                        me: res.data.data.me_name,
                        ta: res.data.data.ta_name,
                        qus_msgt: qus_msg,
                        is_special: res.data.data.is_special,
                        hui: res.data.data.hui,
                        month_good: res.data.data.month_good,
                        day_good: res.data.data.day_good,
                        last_num_text: res.data.data.last_num_text,
                        date_diff: res.data.data.date_diff
                    })
                    wx.removeStorageSync('reverse');

                } else {
                    wx.showModal({
                        title: '错误提示',
                        content: res.data.msg,
                        showCancel: false,
                        success(res) {
                            if (res.confirm) {
                                wx.navigateTo({
                                    url: '/pages/personal/me',
                                })
                            }
                        }
                    });
                }
            }
        })
    },
    // 发送给朋友
    onShareAppMessage: function () {
        var that = this;
        return {
            title: '天纪云',
            path: 'pages/result5/index?id=' + that.data.id + '&is_share=1' + '&history_id=' + that.data.history_id + '&types=' + that.data.queryTypes + '&itypes=' + that.data.itypes,
            // imageUrl: '../../resources/logo.jpg'
        }
    },
    tz() {
        var that = this;
        wx.navigateTo({
            url: '/pages/result5/index?id=' + that.data.id + '&is_share=1' + '&history_id=' + that.data.history_id + '&types=' + that.data.queryTypes + '&itypes=' + that.data.itypes,
        })
    },
    // 分享到朋友圈
    onShareTimeline: function () {
        var that = this;
        return {
            title: '天纪云',
            path: 'pages/result5/index?id=' + that.data.id + '&is_share=1' + '&history_id=' + that.data.history_id + '&types=' + that.data.queryTypes + '&itypes=' + that.data.itypes,
            // imageUrl: '../../resources/logo.jpg'
        }
    },
    bindPickerChange: function (e) {
        let that = this
        let rate = e.detail.value
        let history_id = this.data.history_id
        if (this.data.index == rate) {
            return
        }
        console.log('picker发送选择改变，携带值为', e.detail.value)

        let reqUri = app.globalData.domain + 'v4/index/setRate';
        wx.showModal({
            title: '温馨提示',
            showCancel: true,
            content: '请确认是否调整监测预警推送频率',
            success(res) {
                if (res.confirm) {
                    wx.request({
                        url: reqUri,
                        data: {
                            history_id: history_id,
                            rate: rate,
                        },
                        success(res) {
                            if (res.data.code == app.globalData.successCode) {
                                that.setData({
                                    index: rate
                                })
                            }
                        }
                    })
                }
            }
        })
    },

    /**
     * 折叠面板
     */
    changeIcon(e) {
        let seq = e.currentTarget.dataset.seq;
        let arr = this.data.activeNames;

        if (arr.indexOf(seq) > 0) {
            arr[seq] = 0;
            this.data.activeNames = arr;
            this.setData({
                activeNames: arr
            });
            // console.log('有--删除::', arr, this.data.activeNames);
        } else {
            arr[seq] = seq;
            this.data.activeNames = arr;
            this.setData({
                activeNames: arr
            });
            // console.log('无--删除::', arr, this.data.activeNames);        
        }
    },
    //点击 对方的想法
    toHisAngle: function (e) {
        //第一步 验证是否有可用次数
        let that = this
        let cacheUserInfo = wx.getStorageSync('user_phone');
        wx.setStorageSync('reverse', 1);
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : ''
        wx.request({
            url: app.globalData.domain + 'v4/index/getUserIsUse',
            data: {
                user_phone: user_phone,
                type: that.data.cid3,
            },
            success(res) {
                if (res.data.code == 0) {
                    if (res.data.data.is_used == 1) {
                        that.latestPersonPredict();
                    } else {
                        that.setData({
                            payShow: true
                        });
                    }
                }
            }
        })
    },
    /**
     * 提交ai预测
     */
    latestPersonPredict: function () {
        // 判断当前用户, 是否可以免费次数
        let cacheUserInfo = wx.getStorageSync('user_phone');
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : ''
        let that = this
        let reqUri = app.globalData.domain + 'v4/index/latestPersonPredict';
        let xquestion_id = 0;
        wx.getStorage({
            key: 'questionInfo',
            success(questionInfo) {
                //个人  情感第一个和第三个换位预测,工作最后一个和第四个换位预测
                if (questionInfo.data.question_id == 8) {
                    xquestion_id = 10
                }
                if (questionInfo.data.question_id == 54) {
                    xquestion_id = 7
                }
                if (questionInfo.data.question_id == 10) {
                    xquestion_id = 8
                }
                if (questionInfo.data.question_id == 7) {
                    xquestion_id = 54
                }
                wx.request({
                    url: reqUri,
                    data: {
                        user_phone: user_phone,
                        question_id: xquestion_id,
                        title1: questionInfo.data.title1,
                        title2: questionInfo.data.title2,
                        title3: questionInfo.data.title3,
                        date1: questionInfo.data.date1,
                        startdate: questionInfo.data.startdate,
                        enddate: questionInfo.data.enddate,
                        contact: questionInfo.data.contact,
                    },
                    success(res) {
                        console.log(res)
                        if (res.data.code == app.globalData.successCode) {
                            //跳转loading页
                            wx.navigateTo({
                                url: '/pages/loading/loading?history_id=' + res.data.data.history_id + '&cid3=' + that.data.cid3 + '&xzdata1=' + that.data.xzdata1 + '&xztype=' + that.data.xztype + '&question_id=' + xquestion_id,
                            })
                        } else {
                            Toast(res.data.msg);
                        }
                    }
                })
            }
        })
    },
    /**
     * 付费预测
     */
    toPayLoading: function (e) {
        let that = this
        // 判断当前用户, 是否可以免费次数
        let cacheUserInfo = wx.getStorageSync('user_phone');
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : ''
        let combo_type = e.currentTarget.dataset.combo_type; //套餐类型
        let types = 2;
        if (that.data.question_id == 10 || that.data.question_id == 8) {
            types = 3;
        }
        // 弹窗提示
        wx.showModal({
            title: '温馨提示',
            content: '即将发起支付!',
            success(res) {
                if (res.confirm) { //确认
                    wx.request({
                        url: app.globalData.domain + 'v3/index/intoOrder',
                        data: {
                            type: types,
                            combo_type: combo_type,
                            user_phone: user_phone
                        },
                        success: function (res) {
                            console.log(res)
                            if (res.data.code != 0) {
                                wx.showModal({
                                    title: '温馨提示',
                                    showCancel: false,
                                    content: res.data.msg
                                })
                                return;
                            }
                            // 发起支付
                            wx.requestPayment({
                                timeStamp: res.data.data.timeStamp,
                                nonceStr: res.data.data.nonceStr,
                                package: res.data.data.package,
                                signType: res.data.data.signType,
                                paySign: res.data.data.paySign,
                                success(res) {
                                    console.log('debug支付成功');
                                    that.latestPersonPredict()
                                },
                                fail(res) {
                                    wx.showModal({
                                        title: '温馨提示',
                                        showCancel: false,
                                        content: '支付失败!'
                                    })
                                    return;
                                }
                            })
                        }
                    })
                }
            }
        })

    },
    //显示页面隐藏的结果
    showRes: function (e) {
        console.log(12313213)
        //刷新当前页
        const pages = getCurrentPages()
        const perpage = pages[pages.length - 1] //当前页面
        const keyList = Object.keys(perpage.options) //当前页面携带的路由参数

        if (keyList.length > 0) {
            let keys = '?'
            keyList.forEach((item, index) => {
                if (item == 'isHidden') {
                    perpage.options[item] = 1;
                }
                index === 0 ? keys = keys + item + '=' + perpage.options[item] : keys = keys + '&' + item + '=' + perpage.options[item]
            })
            wx.reLaunch({
                url: '/' + perpage.route + keys + '&isHidden=1'
            })
        } else {
            wx.reLaunch({
                url: '/' + perpage.route //当前页面路由地址
            })
        }
    },
    /**
     * 解决方案付费
     */
    resolvePay: function (e) {
        let that = this;
        let cacheUserInfo = wx.getStorageSync('user_phone');
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : '';
        //支付类型 1 解决方案 2 预测时间
        let type = e.currentTarget.dataset.itype;
        wx.request({
            url: app.globalData.domain + 'v3/index/resolveOrder',
            data: {
                history_id: that.data.history_id,
                user_phone: user_phone,
                type: type
            },
            success: function (res) {
                console.log(res)
                if (res.data.code != 0) {
                    wx.showModal({
                        title: '温馨提示',
                        showCancel: false,
                        content: res.data.msg
                    })
                    return;
                }
                // 发起支付
                wx.requestPayment({
                    timeStamp: res.data.data.timeStamp,
                    nonceStr: res.data.data.nonceStr,
                    package: res.data.data.package,
                    signType: res.data.data.signType,
                    paySign: res.data.data.paySign,
                    success(res) {
                        console.log('debug支付成功');

                        //刷新当前页
                        const pages = getCurrentPages()
                        const perpage = pages[pages.length - 1] //当前页面
                        const keyList = Object.keys(perpage.options) //当前页面携带的路由参数

                        if (keyList.length > 0) {
                            let keys = '?'
                            keyList.forEach((item, index) => {
                                index === 0 ?
                                    keys = keys + item + '=' + perpage.options[item] : keys = keys + '&' + item + '=' + perpage.options[item]
                            })
                            wx.reLaunch({
                                url: '/' + perpage.route + keys
                            })
                        } else {
                            wx.reLaunch({
                                url: '/' + perpage.route //当前页面路由地址
                            })
                        }
                    },
                    fail(res) {
                        wx.showModal({
                            title: '温馨提示',
                            showCancel: false,
                            content: '支付失败!'
                        })
                        return;
                    }
                })
            }
        })

    },
    //看广告免费咨询
    resolveAd: function (e) {
        let that = this;
        let type = e.currentTarget.dataset.itype;
        let cacheUserInfo = wx.getStorageSync('user_phone');
        let user_phone = (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : '';
        let videoAd;
        if (wx.createRewardedVideoAd) {
            videoAd = wx.createRewardedVideoAd({
                adUnitId: 'adunit-b35cfe40852d6b0f'
            })
            videoAd.onLoad(() => {})
            videoAd.onError((err) => {
                console.error('激励视频光告加载失败', err)
            })
            videoAd.onClose((res) => {
                videoAd.offClose()
                if (res && res.isEnded) {
                    if (!videoAd) return

                    videoAd.offClose();
                    // 正常播放结束，可以下发游戏奖励
                    console.log('111');
                    wx.request({
                        url: app.globalData.domain + 'v4/index/adShow',
                        data: {
                            history_id: that.data.history_id,
                            user_phone: user_phone,
                            type: type
                        },
                        success: function (res) {
                            console.log(res)
                            if (res.data.code != 0) {
                                wx.showModal({
                                    title: '温馨提示',
                                    showCancel: false,
                                    content: res.data.msg
                                })
                                return;
                            }
                            //刷新当前页
                            const pages = getCurrentPages()
                            const perpage = pages[pages.length - 1] //当前页面
                            const keyList = Object.keys(perpage.options) //当前页面携带的路由参数

                            if (keyList.length > 0) {
                                let keys = '?'
                                keyList.forEach((item, index) => {
                                    index === 0 ?
                                        keys = keys + item + '=' + perpage.options[item] : keys = keys + '&' + item + '=' + perpage.options[item]
                                })
                                wx.reLaunch({
                                    url: '/' + perpage.route + keys
                                })
                            } else {
                                wx.reLaunch({
                                    url: '/' + perpage.route //当前页面路由地址
                                })
                            }
                        }
                    })
                } else {
                    console.log('000')
                    // 播放中途退出，不下发游戏奖励
                }
            })
        }

        // 用户触发广告后，显示激励视频广告
        if (videoAd) {
            videoAd.show().catch(() => {
                // 失败重试
                videoAd.load()
                    .then(() => videoAd.show())
                    .catch(err => {
                        console.error('激励视频 广告显示失败', err)
                    })
            })
        }

    },
    toService: function () {
        wx.navigateTo({
            url: '/pages/result5/service',
        })
    },
    //   点击查看2024-2043， 展示 会与不会
    showDate: function () {
        let that = this;
        // 点击查看 立即隐藏
        that.setData({
            hiddenClick: 0,
            showDateIsCan: 1
        });
    }

})